package cn.net.dpi.core.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;


public class OnlyNumAndAlphaValidator implements ConstraintValidator<OnlyNumAndAlpha, String> {

    private static final String PATTERN = "^[A-Za-z0-9]+$";

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (s == null) {
            return true;
        }

        return Pattern.matches(PATTERN, s);
    }
}
